home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / dialog.zip / ORDERS.PAS < prev   
Pascal/Delphi Source File  |  1991-03-19  |  6KB  |  186 lines

  1. { Orders.pas -Order entry and dialog demonstration}
  2.  
  3. {$x+}
  4.  
  5. PROGRAM Orders;
  6.  
  7. Uses Objects, Drivers, Views, Menus, App, Dialogs, Diag;
  8.  
  9. CONST
  10.   cmAbout  = 100;     {About-program command number          }
  11.   cmSave   = 101;     {Save command number (not implemented) }
  12.   cmOrder  = 102;     {Order-Entry command number            }
  13.  
  14. TYPE
  15. {- Order record to match order-entry dialog box }
  16. OrderInfoRec = RECORD
  17.   OToppings: Word;               {Toppings check boxes       }
  18.   OSize: Word;                   {Size radio buttons         }
  19.   OStyle: Word;                  {Style radio buttons        }
  20.   ONumber: String[4];            {Number input box           }
  21.   OName: String[64];             {Customer name input box    }
  22.   OPhone: String[64];            {Customer phone input box   }
  23. END;
  24.  
  25. {-Application object }
  26. PTheApp = ^TheApp;
  27. TheApp = OBJECT(TApplication)
  28.    CONSTRUCTOR Init;
  29.    PROCEDURE HandleEvent (VAR Event: TEvent); virtual;
  30.    PROCEDURE InitMenuBar; virtual;
  31. END;
  32.  
  33. VAR
  34.  
  35.   Order: OrderInfoRec;           { Global order (represents database) }
  36.  
  37. {-Initialize global Order variable }
  38. PROCEDURE NewOrder;
  39. BEGIN
  40.   WITH Order DO
  41.   BEGIN
  42.     OToppings := 0;               { Change settings to affect initial }
  43.     OSize     := 0;               {  contents of order-entry dialog   }
  44.     OStyle    := 0;
  45.     ONumber   :='';
  46.     OName     :='';
  47.     OPhone    :='';
  48.     END
  49.   END;
  50. {-Construct application object }
  51. CONSTRUCTOR TheApp.Init;
  52. BEGIN
  53.   TApplication.Init;              {Call ancestor constructor }
  54.   NewOrder                        {Initialize order variable }
  55. END;
  56. {-Respond to various events }
  57. PROCEDURE TheApp.HandleEvent (VAR Event: TEvent);
  58. VAR
  59.   Result: Boolean;
  60.  
  61.   {-Create and execute order-entry dialog }
  62.   FUNCTION OrderDialog: Word;
  63.   VAR
  64.     Dialog: PDialog;              { Pointer to TDialog object        }
  65.     V: PView;                     { For creating various controls    }
  66.     R: TRect;                     { For specitying various rectangles}
  67.     C: Word;                      { Holds result of dialog execution }
  68. BEGIN
  69.   {-Create the dialog object }
  70.   R.Assign(0, 0, 64, 15);
  71.   Dialog := New(PDialog, Init(r, 'Order Dialog'));
  72.   WITH Dialog^ Do
  73.   BEGIN
  74.     Options := Options OR ofCentered;      {Center dialog window}
  75.  
  76.     {-Create Toppings check boxes }
  77.     R.Assign(3, 2, 21, 8);
  78.     V := New(PCheckBoxes, Init(r,
  79.       NewSItem('Pepperoni',
  80.       NewSItem('Extra Chess',
  81.       NewSItem('Mushroom',
  82.       NewSItem('Anchovy',
  83.       NewSItem('Sausage',
  84.       NIL)))))));
  85.    Insert (V);
  86.    R.Assign(3, 2, 21, 3);
  87.    Insert(New(PLabel, Init(R, 'Toppings', V)));
  88.  
  89.    {-Create Size radio buttons }
  90.    R.Assign(25, 3, 40, 6);
  91.    V := New(PRadioButtons, Init(r,
  92.      NewSItem('Small',
  93.      NewSItem('Medium',
  94.      NewSItem('Large',
  95.      NIL)))));
  96.      Insert (V);
  97.      R.Assign(25, 3, 40, 3);
  98.      Insert(New(PLabel, Init(R, 'Size', V)));
  99.  
  100.      {-Create Style radio buttons }
  101.      R.Assign(44, 3, 61, 5);
  102.      V:= New(PRadioButtons, Init(R,
  103.        NewSItem('Thin Crust',
  104.        NewSItem('Thick Crust',
  105.        NIL))));
  106.        Insert (V);
  107.        R.Assign(44, 2, 61, 3);
  108.        Insert(New(PLabel, Init(R, 'Style', V)));
  109.  
  110.        {-Create Number, Name, Phone input boxes }
  111.        R.Assign(52, 6, 61, 7);
  112.        V:= New(PInputLine, Init(r, 4));
  113.        Insert (V);
  114.        R.Assign(44, 6, 51, 7);
  115.        Insert(New(PLabel, Init(R, 'Number', V)));
  116.        R.Assign(25, 8, 61, 9);
  117.        V:= New(PInputLine, Init(R, 64));
  118.        Insert (V);
  119.        R.Assign(25, 7, 61, 8);
  120.        Insert (New(PLabel, Init(R, 'Customer Name', V)));
  121.        R.Assign(25, 10, 61, 11);
  122.        V:= New(PInputLine, Init(R, 64));
  123.        Insert (V);
  124.        R.Assign(25, 9, 61, 10);
  125.        Insert(New(PLabel, Init(R, 'Customer Phone', V)));
  126.  
  127.        {- Create Cancel and OK buttons }
  128.        R.Assign(30,12, 40, 14);
  129.        Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
  130.        R.Assign(45, 12, 55, 14);
  131.        Insert(New(PButton, Init(R, 'O~k~', cmOK, bfDefault)));
  132.  
  133.       END;
  134.  
  135.       {-Perform dialog}
  136.       Dialog^.SetData(Order);
  137.       C:= Desktop^.ExecView(Dialog);
  138.       IF C <> cmCancel THEN Dialog^.GetData(Order);
  139.       Dispose(Dialog, Done);
  140.       OrderDialog := C             {So caller can inspect result}
  141.       END;
  142.    BEGIN {TheApp.HandleEvent}
  143.      IF (Event.What = evCommand) AND (Event.Command = cmQuit) THEN
  144.        IF NOT Yes('Quit now?') THEN ClearEvent(Event);
  145.      TApplication.HandleEvent(Event);
  146.      IF Event.What = evCommand THEN
  147.      BEGIN
  148.        CASE Event.Command OF
  149.          cmAbout: AboutProgram('Order-Entry Demonstration');
  150.          cmSave:  ErrorMessage(999, 'Feature not implemented');
  151.          cmORder: IF OrderDialog<> cmCancel
  152.                  THEN {Save order}
  153.                  ELSE NewOrder;
  154.         ELSE
  155.           Exit
  156.         END;
  157.         ClearEvent(Event)
  158.       END
  159.      END;
  160.  
  161.      PROCEDURE TheApp.InitMenuBar;
  162.      VAR R: TRect;
  163.      BEGIN
  164.        GetExtent (R);
  165.        R.B.Y := R.A.Y + 1;
  166.        MenuBar := New (PMenuBar, Init(R, NewMenu(
  167.          NewSubMenu('~M~enu', hcNoContext, NewMenu(
  168.          NewItem('~A~bout','',kbNoKey, cmAbout, hcNoContext,
  169.          NewItem('~S~ave','',kbNoKey, cmSave, hcNoContext,
  170.          NewItem('~O~rder','', kbNoKey, cmOrder, hcNoContext,
  171.          NewLine(
  172.          NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoCOntext,
  173.          NIL)))))),
  174.        NIL))
  175.      ))
  176.    END;
  177.  
  178.    VAR
  179.      Application: TheApp;
  180.  
  181.      BEGIN
  182.        Application.Init;
  183.        Application.Run;
  184.        Application.Done
  185.      END.
  186.